Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleGenerated java files
File: MyBits.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160718.test;
import java.util.BitSet;
import java.util.Objects;
import com.google.common.base.MoreObjects;
/**
 * Represents the implementation of myBits.
 */
public final class MyBits {
    private BitSet bits;
    /**
     * Creates an instance of myBits.
     */
    private MyBits() {
    }
    /**
     * Creates an instance of myBitsForTypeBits.
     *
     * @param value value of myBitsForTypeBits
     */
    public MyBits(BitSet value) {
        this.bits = value;
    }
    /**
     * Returns the object of myBitsForTypeBits.
     *
     * @param value value of myBitsForTypeBits
     * @return Object of myBitsForTypeBits
     */
    public static MyBits of(BitSet value) {
        return new MyBits(value);
    }
    /**
     * Returns the attribute bits.
     *
     * @return value of bits
     */
    public BitSet bits() {
        return bits;
    }
    @Override
    public int hashCode() {
        return Objects.hash(bits);
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof MyBits) {
            MyBits other = (MyBits) obj;
            return
                 Objects.equals(bits, other.bits);
        }
        return false;
    }
    @Override
    public String toString() {
        return bits.toString();
    }
    /**
     * Returns the object of myBits fromString input String.
     *
     * @param valInString input String
     * @return Object of myBits
     */
    public static MyBits fromString(String valInString) {
        try {
            BitSet tmpVal = new BitSet();
            valInString = valInString.replace('{', ' ');
            valInString = valInString.replace('}', ' ');
            valInString = valInString.trim();
            String[] bitsTemp = valInString.split(",", 0);
            for (String bitTemp : bitsTemp) {
                bitTemp = bitTemp.trim();
                tmpVal.set(Integer.parseInt(bitTemp));
            };
            return of(tmpVal);
        } catch (Exception e) {
        }
        return null;
    }
}


 

Binary

 

Overview
The binary built-in type represents any binary data, i.e., a sequence
of octets.

 

A binary can be restricted with the "length" statement. The length of a binary value is the number of octets it
contains.

 

Binary values are encoded with the base64 encoding scheme

 

Java mapping
Byte array is used to store decoded binary during code generation.

 

Example

 

Code Block
titleinput YANG file
File : test.yangmodule Test {
 yang-version 1;
 namespace http://huawei.com;
 prefix Ant;
 typedef MyBinary {
 type binary {
 length "4";
 }
 }
}

 

Code Block
titleGenerated java files
File: MyBinary.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160718.test;
import java.util.Objects;
import com.google.common.base.MoreObjects;
import java.util.Base64;
/**
 * Represents the implementation of myBinary.
 */
public final class MyBinary {
 private byte[] binary;
 /**
 * Creates an instance of myBinary.
 */
 private MyBinary() {
 }
 /**
 * Creates an instance of myBinaryForTypeBinary.
 *
 * @param value value of myBinaryForTypeBinary
 */
 public MyBinary(byte[] value) {
 this.binary = value;
 }
 /**
 * Returns the object of myBinaryForTypeBinary.
 *
 * @param value value of myBinaryForTypeBinary
 * @return Object of myBinaryForTypeBinary
 */
 public static MyBinary of(byte[] value) {
 return new MyBinary(value);
 }
 /**
 * Returns the attribute binary.
 *
 * @return value of binary
 */
 public byte[] binary() {
 return binary;
 }
 @Override
 public int hashCode() {
 return Objects.hash(binary);
 }
 @Override
 public boolean equals(Object obj) {
 if (this == obj) {
 return true;
 }
 if (obj instanceof MyBinary) {
 MyBinary other = (MyBinary) obj;
 return
 Objects.equals(binary, other.binary);
 }
 return false;
 }
 @Override
 public String toString() {
 return Base64.getEncoder().encodeToString(binary);
 }
 /**
 * Returns the object of myBinary fromString input String.
 *
 * @param valInString input String
 * @return Object of myBinary
 */
 public static MyBinary fromString(String valInString) {
 try {
 byte[] tmpVal = Base64.getDecoder().decode(valInString);;
 return of(tmpVal);
 } catch (Exception e) {
 }
 return null;
 }
}



Golden Eye Demo 

Link: https://www.youtube.com/watch?v=ipbu0x0LcDk

...