Skip to main content

Using Tags

In order to represent data, ODS uses Tags. In order to save data to a file/memory, you need to create a tag to wrap that data.

Tag Types

A tag for every primary data type exists (plus a few advanced one.) While similar for the most part, there can be some variation in the name of tags for each implementation of ODS. Below is a table with all of the names.

JavaC#Rust
StringTagStringTagStringTag
IntegerTagIntegerTagIntegerTag
FloatTagFloatTagFloatTag
DoubleTagDoubleTagDoubleTag
LongTagLongTagLongTag
ByteTagByteTagByteTag
ListTagListTagVectorTag
MapTagDictionaryTagN/A
ObjectTagObjectTagObjectTag
Compressed ObjectCompressed ObjectN/A

Creating a Tag

Creating a tag is a very simple process. All you need to do is construct that tag and provide it with the name and the value of the tag.

import me.ryandw11.ods.tags;

StringTag stringTag = new StringTag("MyString", "My Value!");

The code above will create a new StringTag for you to use. All of the other tags have the exact same syntax for creating them. It is the name followed by the value.

Saving Tags

ODS allows you to save a list of tags to a file (or the memory buffer). When using the save method, the file or buffer is overwritten causing all data already there to be deleted. (If the file does not exist, ODS will automatically create it.)

ObjectDataStructure ods = new ObjectDataStructure(new File("test.ods"));

List<Tag<?>> tags = new ArrayList<>();
StringTag stringTag = new StringTag("MyString", "My Value!");
tags.add(stringTag);

ods.save(tags);

Appending Tags

Overwriting the data in a file/buffer is often not very convenient, that is why ODS offers the ability to append tags to the end of the file/buffer.

ObjectDataStructure ods = new ObjectDataStructure(new File("test.ods"));

StringTag stringTag = new StringTag("MyString", "My Value!");

ods.append(stringTag);

You can also use appendAll to append a list of tags to the end of the file/buffer.

Additional Notes

Utility methods and macros exist in the different implementations to make it easier (to an extent) to create tags.

In Java you can use the ODS utility class to wrap supported data types into Tags. (This can also serialize classes into ObjectTags. See the serialization section for more info).

StringTag stringTag = ODS.wrap("MyString", "My Value!");
IntTag intTag = ODS.wrap("MyInt", 20);