com.h3c.util.snmp

## Class SnmpField

- java.lang.Object
- - com.h3c.util.snmp.SnmpField

- Direct Known Subclasses:
    SnmpRequest, SnmpResponse

      public class SnmpField
      extends Object

  ASN.1 BER field (type, length and value).

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static SnmpField` | `NULL_FIELD`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SnmpField()` Default constructor for NULL type.
    `SnmpField(byte[] v)` Constructor for OCTET_STR type.
    `SnmpField(int v)` Constructor for INTEGER type.
    `SnmpField(IpAddress v)` Constructor for IP_ADDRESS.
    `SnmpField(long v)` Constructor for COUNTER64 type.
    `SnmpField(SnmpFieldType type, byte[] v)` Constructor for binary types.
    `SnmpField(SnmpFieldType type, long v)` Constructor for scalar types.
    `SnmpField(SnmpOid v)` Constructor for OID type.
    `SnmpField(String v)` Constructor for OCTET_STR type

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `asBoolean()`
    `byte[]` | `asBytes()`
    `int` | `asInt()`
    `IpAddress` | `asIpAddress()`
    `long` | `asLong()`
    `MacAddress` | `asMacAddress()`
    `SnmpOid` | `asOid()`
    `String` | `asString()`
    `String` | `asStringValue()` This method should only be used when you just want to display the result.
    `String` | `asTimeTicksString()`
    `SnmpFieldType` | `getType()`
    `void` | `read(ByteBuffer in)` Recursively decode the buffer into a field.
    `SnmpField` | `set(byte[] v)` Convenience method for OCTET_STR values.
    `SnmpField` | `set(int v)` Convenience method for INTEGER 32-bit values (allows for negatives).
    `SnmpField` | `set(IpAddress val)` Used to set IP_ADDRESS value.
    `SnmpField` | `set(long v)` Convenience method for COUNTER64 values.
    `SnmpField` | `set(SnmpFieldType type, byte[] val)` Used to set a specific type of value.
    `SnmpField` | `set(SnmpFieldType type, long val)` Used to set a specific type of value.
    `SnmpField` | `set(SnmpOid val)` Used to set OID value.
    `SnmpField` | `set(String v)` Convenience method for OCTET_STR values.
    `SnmpField` | `setNull()` Convenience method reseting the field to null.
    `SnmpField` | `setType(SnmpFieldType type)`
    `SnmpField` | `setU32(long v)` Convenience method for COUNTER32 values (converts to positive long).
    `String` | `toDebugString()` Returns a string representation of this field.
    `String` | `toString()`
    `int` | `write(ByteBuffer out)` Recursively encode this field into the buffer.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### NULL_FIELD

          public static final SnmpField NULL_FIELD

  - ### Constructor Detail

    - #### SnmpField

          public SnmpField()

      Default constructor for NULL type.

    - #### SnmpField

          public SnmpField(int v)

      Constructor for INTEGER type.
      Parameters:
        `v` - value

    - #### SnmpField

          public SnmpField(long v)

      Constructor for COUNTER64 type.
      Parameters:
        `v` - value

    - #### SnmpField

          public SnmpField(byte[] v)

      Constructor for OCTET_STR type.
      Parameters:
        `v` - value

    - #### SnmpField

          public SnmpField(String v)

      Constructor for OCTET_STR type
      Parameters:
        `v` - value

    - #### SnmpField

          public SnmpField(IpAddress v)

      Constructor for IP_ADDRESS.
      Parameters:
        `v` - value

    - #### SnmpField

          public SnmpField(SnmpOid v)

      Constructor for OID type.
      Parameters:
        `v` - value

    - #### SnmpField

          public SnmpField(SnmpFieldType type,
                   long v)

      Constructor for scalar types.
      Parameters:
        `type` - encoding type
        `v` - value

    - #### SnmpField

          public SnmpField(SnmpFieldType type,
                   byte[] v)

      Constructor for binary types.
      Parameters:
        `type` - encoding type
        `v` - value

  - ### Method Detail

    - #### set

          public SnmpField set(int v)

      Convenience method for INTEGER 32-bit values (allows for negatives).
      Parameters:
        `v` - signed 32-bit value
      Returns:
        this instance
      See Also:
        `Codec.decodeLong(byte[], com.h3c.util.snmp.SnmpFieldType)`, `setU32(long)`

    - #### setU32

          public SnmpField setU32(long v)

      Convenience method for COUNTER32 values (converts to positive long).
      Parameters:
        `v` - unsigned 32-bit value
      Returns:
        this instance

    - #### set

          public SnmpField set(long v)

      Convenience method for COUNTER64 values.
      Parameters:
        `v` - long value
      Returns:
        this instance

    - #### set

          public SnmpField set(String v)

      Convenience method for OCTET_STR values.
      Parameters:
        `v` - string value
      Returns:
        this instance

    - #### set

          public SnmpField set(byte[] v)

      Convenience method for OCTET_STR values.
      Parameters:
        `v` - byte array value
      Returns:
        this instance

    - #### set

          public SnmpField set(SnmpFieldType type,
                      long val)

      Used to set a specific type of value.
      Parameters:
        `type` - value type (COUNTER32, COUNTER64, etc.)
        `val` - integer/long value
      Returns:
        this instance
      See Also:
        `setU32(long)`, `set(int)`

    - #### set

          public SnmpField set(SnmpFieldType type,
                      byte[] val)

      Used to set a specific type of value.
      Parameters:
        `type` - value type (OCTET_STR, OPAQUE, etc.)
        `val` - byte array value
      Returns:
        this instance

    - #### setNull

          public SnmpField setNull()

      Convenience method reseting the field to null.
      Returns:
        this instance

    - #### set

          public SnmpField set(IpAddress val)

      Used to set IP_ADDRESS value.
      Parameters:
        `val` - IP address value
      Returns:
        this instance

    - #### set

          public SnmpField set(SnmpOid val)

      Used to set OID value.
      Parameters:
        `val` - OID value
      Returns:
        this instance

    - #### asInt

          public int asInt()

    - #### asLong

          public long asLong()

    - #### asBytes

          public byte[] asBytes()

    - #### asString

          public String asString()

    - #### asBoolean

          public boolean asBoolean()

    - #### asOid

          public SnmpOid asOid()

    - #### asIpAddress

          public IpAddress asIpAddress()

    - #### asMacAddress

          public MacAddress asMacAddress()

    - #### asTimeTicksString

          public String asTimeTicksString()

    - #### read

          public void read(ByteBuffer in)

      Recursively decode the buffer into a field.
      Parameters:
        `in` - input buffer

    - #### write

          public int write(ByteBuffer out)

      Recursively encode this field into the buffer.
      Parameters:
        `out` - ByteBuffer to send as a socket message.
      Returns:
        number of bytes written

    - #### getType

          public SnmpFieldType getType()

    - #### setType

          public SnmpField setType(SnmpFieldType type)

    - #### toDebugString

          public String toDebugString()

      Returns a string representation of this field.
      Returns:
        debug string

    - #### asStringValue

          public String asStringValue()

      This method should only be used when you just want to display the result. If you are manipulating the value use the appropriate "as" method not this one.
      Returns:
        string representation of the value

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2014. All Rights Reserved.