package org.eclipse.linuxtools.ctf.core.event.types;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
/**
* A CTF string declaration.
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class StringDeclaration implements IDeclaration {
+public class StringDeclaration extends Declaration {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private Encoding encoding = Encoding.UTF8;
+ private final Encoding fEncoding;
// ------------------------------------------------------------------------
// Constructors
* Generate a UTF8 string declaration
*/
public StringDeclaration() {
+ fEncoding = Encoding.UTF8;
}
/**
* @param encoding the encoding, utf8 or ascii
*/
public StringDeclaration(Encoding encoding) {
- this.encoding = encoding;
+ fEncoding = encoding;
}
// ------------------------------------------------------------------------
* @return the character encoding.
*/
public Encoding getEncoding() {
- return encoding;
- }
-
- /**
- *
- * @param encoding the character encoding to set
- */
- public void setEncoding(Encoding encoding) {
- this.encoding = encoding;
+ return fEncoding;
}
@Override
// See ctf 4.2.5: Strings are always aligned on byte size.
return 8;
}
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public int getMaximumSize() {
+ return Integer.MAX_VALUE;
+ }
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ /**
+ * @since 3.0
+ */
@Override
public StringDefinition createDefinition(IDefinitionScope definitionScope,
- String fieldName) {
- return new StringDefinition(this, definitionScope, fieldName);
+ String fieldName, BitBuffer input) throws CTFReaderException {
+ String value = read(input);
+ return new StringDefinition(this, definitionScope, fieldName, value);
}
+ private String read(BitBuffer input) throws CTFReaderException {
+ /* Offset the buffer position wrt the current alignment */
+ alignRead(input);
+
+ StringBuilder sb = new StringBuilder();
+ char c = (char) input.get(8, false);
+ while (c != 0) {
+ sb.append(c);
+ c = (char) input.get(8, false);
+ }
+ return sb.toString();
+ }
@Override
public String toString() {
/* Only used for debugging */